#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

void Merge(vector<int> &nums, int low, int mid, int high)
{
    int k = low, i, j;
    vector<int> B(nums.size() + 1, 0);
    for (; k <= high; k++)
    {
        B[k] = nums[k];
    }
    for (i = low, j = mid + 1, k = i; i <= mid && j <= high; k++)
    {
        if (B[i] <= B[j])
        {
            nums[k] = B[i++];
        }
        else
        {
            nums[k] = B[j++];
        }
    }
        while (i <= mid)
            nums[k++] = B[i++];
        while (j <= high)
            nums[k++] = B[j++];
}//调好啦，一个括号毁所有(-_-)......

void Mergesort(vector<int> &nums, int low, int high)
{
    if (low < high)
    {
        int mid = (low + high) >> 1;
        Mergesort(nums, low, mid);
        Mergesort(nums, mid + 1, high);
        Merge(nums, low, mid, high);
    }
}

int main()
{
    vector<int> nums ={1,5,2,4,4,4,4,4,3};
    Mergesort(nums, 0, nums.size() - 1);
    for (int i = 0; i < nums.size(); i++)
    {
        cout << nums[i] << " ";
    }
}